import os
import osconfig
from build_tools import *

sys.path.append(Env['OS_ROOT'] + '/drivers/hal/st/scripts/')
import prebuild
prebuild.prebuild(Env['BSP_ROOT'])

pwd = PresentDir()

# add general drivers
src = Split('''
board.c
CubeMX_Config/Src/bsp.c
CubeMX_Config/Src/stm32l4xx_it.c
CubeMX_Config/Src/stm32l4xx_hal_msp.c
CubeMX_Config/Src/system_stm32l4xx.c
''')

# path   include path in project
path =  [pwd]
path += [pwd + '/CubeMX_Config/Inc']
path += [pwd + '/ports']

if osconfig.CROSS_TOOL == 'gcc':
    src += [pwd + '/startup/startup_stm32l475xx_gcc.s']
elif osconfig.CROSS_TOOL == 'keil':
    src += [pwd + '/startup/startup_stm32l475xx_arm.s']
elif osconfig.CROSS_TOOL == 'iar':
    src += [pwd + '/startup/startup_stm32l475xx_iar.s']

CPPDEFINES = ['STM32L475xx'] 
group = AddCodeGroup('bsp', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
